package Analizer;

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Image;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.Serializable;
import java.util.Iterator;
import java.util.Vector;

import javax.swing.Box;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.border.BevelBorder;

/**
 * 
 * @author Tomek2
 * przechowuje krzywa wraz z erementami guli lista
 */
public class iElement extends JPanel implements Serializable {
	
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	public int [][] iKrzywa; // krzywa
	public double iTotalTimesKrzywej;
	public double iDlKrzywa;
	
	private JLabel lblNewLabel;
	private Iterator it;
	private boolean iFalagaPrzerwy = true;
	private Image iIkona;
	JCheckBox iCheckBox_Element;

	/**
	 * Create the panel.
	 */
	public iElement (Vector<i_Punkt> krzywa) {
		Iterator <i_Punkt> it = krzywa.iterator();
		/**
		 *  OBLICZ CZAS CALEGO RUCHU - przydatne do sortowania 
		 *  i wyboru Schematu, a takze przy wyliczeniu skalowania
		 */
		iKrzywa = new int[krzywa.size()][3];
		int x=0;
		while (it.hasNext()){
			i_Punkt pt = it.next();
			this.iTotalTimesKrzywej += pt.intervTime;
			this.iKrzywa [x][0] = pt.x;
			this.iKrzywa [x][1] = pt.y;
			this.iKrzywa [x][2] = (int) pt.intervTime;
			x++;
			}
		
		/**
		 * DLUGOSC KRZYWEJ
		 */
		this.iDlKrzywa = Math.hypot(iKrzywa[0][0] - iKrzywa[iKrzywa.length-1][0], iKrzywa[0][1] - iKrzywa[iKrzywa.length-1][1]) ;
		
		/**
		 * INCJALIZUJ OKNO
		 */
		Init();
		}
	
	private void Init(){
		setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
		setBackground(SystemColor.window);
		setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
		
		lblNewLabel = new JLabel("dl");
		lblNewLabel.setHorizontalAlignment(SwingConstants.LEFT);
		add(lblNewLabel);
		
		Box horizontalBox = Box.createHorizontalBox();
		add(horizontalBox);
		
		iCheckBox_Element = new JCheckBox("");
		iCheckBox_Element.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(iCheckBox_Element.isSelected()){
					System.out.println("Jest zaznaczony");
					setBackground(new Color(177,211,152));
				} else {
					System.out.println("Nie jest zaznaczony");
					setBackground(SystemColor.window);
				}
			}
			});
		iCheckBox_Element.setBounds(232, 6, 28, 23);
		add(iCheckBox_Element);
		
		Box horizontalBox_2 = Box.createHorizontalBox();
		add(horizontalBox_2);
		
		JLabel i_StartMeta = new JLabel("0.0 d\u0142");
		add(i_StartMeta);
		
		Box horizontalBox_1 = Box.createHorizontalBox();
		add(horizontalBox_1);
		//setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{lblNewLabel, checkBox}));
		
		JLabel lblTotalTimes = new JLabel(""+iTotalTimesKrzywej+" tTim.");
		add(lblTotalTimes);		
		
		JLabel label = new JLabel("");
		add(label);
		}
	
	
	public int [][] iPobierzKrzywa(){
		return this.iKrzywa;
		}
	public double iPobierzCzsKrzywej(){
		return this.iTotalTimesKrzywej;
		}
	public double iPobierzDlKrzywa(){
		return this.iDlKrzywa;
		}
}
